import java.awt.Font;
import java.awt.Frame;
import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

/**
 * 
 *  reader's purchase receipt
 *
 */
public class ReceiptGui extends JDialog {

	private static final long serialVersionUID = 1L;
	/** window panel */
	private JPanel jContentPane = null;
	/** scroll panel for jTable */
	private JScrollPane jScrollPane = null;
	/** table for purchased items */
	private JTable jTable = null;
	/** holds number of rows in the table */
	public int row=2;
	/** column names for the table */
	public String[] ColumnNames={"Item","Price"};
	/** holds purchased items data */
	public String[][] data;
	/** total purchase price label */
	private JLabel price = null;
	/** holds total purchase price */
	public String sum=Main.cart.sum.toString();  //  @jve:decl-index=0:
	/** dispose receipt */
	private JButton jButton = null;

	/**
	 * initialize the variables
	 * @param owner
	 */
	public ReceiptGui(Frame owner,String[][] temp) {
		super(owner);
		data=temp;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 320);
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			price = new JLabel();
			price.setBounds(new Rectangle(15, 201, 245, 34));
			price.setText("Total Price : "+sum+"$");
			price.setFont(new Font(Font.SANS_SERIF ,Font.ITALIC,25));
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJScrollPane(), null);
			jContentPane.add(price, null);
			jContentPane.add(getJButton(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(10, 10, 250, 180));
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTable	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTable() 
	{
		if (jTable == null)
		{
			jTable = new JTable(data,ColumnNames);
			TableColumn column=jTable.getColumnModel().getColumn(0);
			column.setPreferredWidth(230);
			
		}
		return jTable;
	}

	/**
	 * This method initializes jButton and add action listener	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton("OK");
			jButton.setBounds(new Rectangle(18, 240, 240, 36));
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return jButton;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
